home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
btrieve
/
sql_dp.arj
/
XQLMDPMI.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-08-08
|
53KB
|
1,653 lines
unit XQLMDPMI; { XQL-Manager DPMI Interface for Borland/Turbo Pascal 7.0 }
{ Dieter Dasberg }
interface
{$IfDef DPMI}
Uses DOS, WinAPI, SimRMI;
{$EndIf}
{$IfDef Windows}
ERROR : Use the XQLM Windows interface from NOVELL
{$EndIf}
{$IfDef MSDos}
ERROR : Use the XQLM MSDos interface from NOVELL
{$EndIf}
const SQL_WORK_BUFFER_SIZE = 8192; { bytes in MSDOS memory }
STATUS_BUFFER_SIZE = 30; { bytes for the status buffer in }
{ XQLStatus function }
function InitXQLMDPMI : integer; { Call this function before working }
{ with this interface! It first tests }
{ if btrieve and xql/sql are availi- }
{ able and then allocates 3 workbuffer}
{ in MSDOS memory. This makes the new }
{ DPMI interface a little faster. }
procedure ExitXQLMDPMI; { Call this function before leaving }
{ your program to realease the xql- }
{ DPMI workbuffer in MSDOS memory. }
function XQLLogin (var UserId,
Pswd,
DataDic,
DataPath,
Machine;
ProcessId : integer ) : integer;
function XQLLogout : integer;
function XQLCursor (var Cursor : integer ) : integer;
function XQLCompile ( Cursor : integer;
var SLen : integer;
var Stmnt ) : integer;
function XQLFormat ( Cursor,
VPos,
Len : integer;
var MaskBuf ) : integer;
function XQLDescribe ( Cursor,
VPos : integer;
var DType,
Size,
Dec,
DSize,
NLength : integer;
var Name ) : integer;
function XQLFetch ( Cursor,
Op : integer;
var DLen : integer;
var Buf;
var Sel : longint;
ASCII,
Spaces : integer ) : integer;
function XQLSubst ( Cursor,
SCount,
NameLen : integer;
var VarName;
TextLen : integer;
var VarText ) : integer;
function XQLExec ( Cursor : integer ) : integer;
function XQLFree ( Cursor : integer ) : integer;
function XQLStatus ( Cursor,
SubFunc : integer;
var StatBuf ) : integer;
function XQLStop : integer;
function XQLVersion ( VBuffer : longint ) : integer;
function XQLConvert ( Option,
DType,
Size,
Dec,
DSize : integer;
var Value;
var RetValue;
var Mask;
Just : integer ) : integer;
function XQLValidate (var Count : integer;
var FieldName;
BufLen : integer;
var Data ) : integer;
function XQLMask ( Option,
DType,
Size,
Dec : integer;
var MLen : integer;
var Mask ) : integer;
function XQLSpUtility ( Cursor,
Option : integer;
var StmntCnt,
StmntExec : integer;
var BufLen : integer;
var StatBuf ) : integer;
implementation
type tSegOfs = record { 32 bit address }
Offset : word;
Segment : word;
end;
tDosAlloc = record case boolean of
TRUE : (Addresses : LongInt);
FALSE : (Selector : word;
Segment : word; );
end;
tXQLMID = array[0..3] of char;
tXQLMStruc = record { structure passed to XQLM }
XQLMID : tXQLMID;
Fcn : integer;
CursorID : integer;
Stat : integer;
SessionID : integer;
end;
tBtrieve = record
Dumy1 : integer;
BtrOp : integer;
Dumy2 : integer;
Dumy3 : integer;
Dumy4 : integer;
BtrStat : tSegOfs;
end;
tBtrieveStruc = record
XQLMStruc : tXQLMStruc;
BtrieveRec : tBtrieve;
end;
tLogin = record
UserID : tSegOfs;
Pswd : tSegOfs;
DataDic : tSegOfs;
DataPath : tSegOfs;
Machine : tSegOfs;
ProcessId : integer;
end;
tLoginStruc = record
XQLMStruc : tXQLMStruc;
LoginRec : tLogin;
end;
tCompile = record
Len : integer;
Statement : tSegOfs;
end;
tCompileStruc = record
XQLMStruc : tXQLMStruc;
CompileRec : tCompile;
end;
tFormat = record
Position : integer;
MaskLen : integer;
Mask : tSegOfs;
end;
tFormatStruc = record
XQLMStruc : tXQLMStruc;
FormatRec : tFormat;
end;
tFetch = record
Operation : integer;
DataLen : integer;
DataBuf : tSegOfs;
Select : longint;
ASCIIFlag : integer;
Spacing : integer;
end;
tFetchStruc = record
XQLMStruc : tXQLMStruc;
FetchRec : tFetch;
end;
tDescr = record
Position : integer;
DataType : integer;
DataSize : integer;
DecCount : integer;
DispSize : integer;
NameLength : integer;
NameBuf : tSegOfs;
end;
tDescrStruc = record
XQLMStruc : tXQLMStruc;
DescrRec : tDescr;
end;
tSubst = record
Count : integer;
NLen : integer;
VName : tSegOfs;
TLen : integer;
VText : tSegOfs;
end;
tSubstStruc = record
XQLMStruc : tXQLMStruc;
SubstRec : tSubst;
end;
tStatus = record
SubFunctn : integer;
Buf : tSegOfs;
end;
tStatusStruc = record
XQLMStruc : tXQLMStruc;
StatusRec : tStatus;
end;
tVersion = record
Buffer : tSegOfs;
end;
tVersionStruc = record
XQLMStruc : tXQLMStruc;
VersionRec : tVersion;
end;
tConvert = record
ConvFcn : integer;
ConvType : integer;
ConvSize : integer;
ConvDec : integer;
ConvDSize : integer;
ConvVal : tSegOfs;
ConvRet : tSegOfs;
ConvMask : tSegOfs;
ConvJust : integer;
end;
tConvertStruc = record
XQLMStruc : tXQLMStruc;
ConvertRec : tConvert;
end;
tValidate = record
ValCount : integer;
ValField : tSegOfs;
ValBufLen : integer;
ValData : tSegOfs;
end;
tValidateStruc = record
XQLMStruc : tXQLMStruc;
ValidateRec : tValidate;
end;
tMask = record
MaskOption : integer;
MaskType : integer;
MaskSize : integer;
MaskDec : integer;
MaskLen : integer;
MaskVal : tSegOfs;
end;
tMaskStruc = record
XQLMStruc : tXQLMStruc;
MaskRec : tMask;
end;
tSpUtil = record
UtilOption : integer;
UtilStmntCnt : integer;
UtilStmntExec : integer;
UtilBufLen : integer;
UtilStatBuf : tSegOfs;
end;
tSpUtilStruc = record
XQLMStruc : tXQLMStruc;
SpUtilRec : tSpUtil;
end;
pXQLMArray = ^tXQLMArray;
tXQLMArray = array[0..SQL_WORK_BUFFER_SIZE] of char;
tXQLMBuff = record
DPMIAddr : tDosAlloc;
Buffer : pXQLMArray;
end;
pString = ^string;
pInteger = ^integer;
const XQLMBUFFS = 3;
{ XQL func's, "*" means that it is not tested yet! }
FCN_INV = -1; { investigate }
FCN_LOG_IN = 0; { login }
FCN_LOG_OUT = 1; { logout }
FCN_CURSOR = 2; { get cursor }
FCN_COMPILE = 3; { compile statement }
FCN_FORMAT = 4; { format data } { * }
FCN_FETCH = 5; { fetch data }
FCN_DESCRIBE = 6; { describe statement }
FCN_SUBST = 7; { substitute variables }
FCN_EXEC = 8; { execute statement }
FCN_FREE = 9; { free cursor }
FCN_STAT = 10; { status information } { * }
FCN_STOP = 11; { stop xqlm NOT IN DPMI }
FCN_VERS = 12; { version of xqlm } { * }
FCN_CONV = 13; { convert variables } { * }
FCN_VAL = 14; { validate } { * }
FCN_MASK = 15; { mask operation } { * }
FCN_SPUTIL = 16; { special util } { * }
FCN_BTRIEVE = 17; { not XQLM, just needed to have an index }
FCN_XQLM_STRUC = 2; { all func's which uses only the XQLMStruc }
{ use the same buffer (pXQLMStruc) as the }
{ login-func. }
var SQLCode : integer;
Regs : TRealModeRecord;
XQLMBuffer : array[1..XQLMBUFFS] of tXQLMBuff;
XQLMFuncs : array[FCN_LOG_IN..FCN_BTRIEVE] of tDosAlloc;
pXQLMStruc : ^tXQLMStruc;
pBtrieve : ^tBtrieveStruc;
pBtrStat : pInteger;
BStat : integer;
pLogin : ^tLoginStruc;
pUserID : pString;
pPswd : pString;
pDataDic : pString;
pDataPath : pString;
pMachine : pString;
pCompile : ^tCompileStruc;
pFormat : ^tFormatStruc;
pFetch : ^tFetchStruc;
pDescr : ^tDescrStruc;
pSubst : ^tSubstStruc;
pStatus : ^tStatusStruc;
pVersion : ^tVersionStruc;
pConvert : ^tConvertStruc;
pValidate : ^tValidateStruc;
pMask : ^tMaskStruc;
pSpUtil : ^tSpUtilStruc;
const XQLM_ID : tXQLMID = ('X','Q','L','M');
XQLMLoaded : boolean = FALSE;
SessID : integer = -1; { session identifier for XQL }
DPMI_INTERFACE_FAIL = 22222; { any value but no Btrieve/XQL error }
BTRV_NOT_LOADED = 20;
XQLM_NOT_LOADED = 200;
BTR_INT = $7B; { Btrieve interrupt }
DOS_INT = $21; { DOS interrupt }
DPMI_INT = $31; { DPMI real mode interrupt }
BTR_OFFSET = $0033;
FCN_RES_INV_XQLM = 503;
function XQLLogin(var UserId,
Pswd,
DataDic,
DataPath,
Machine;
ProcessId : integer ) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
pLogin^.LoginRec.ProcessID := ProcessID;
with pLogin^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_LOG_IN;
CursorId := 0;
SessionID := SessID;
end;
Move(UserId, pUserID^, SizeOf(string));
Move(Pswd, pPswd^, SizeOf(string));
Move(DataDic, pDataDic^, SizeOf(string));
Move(DataPath, pDataPath^, SizeOf(string));
Move(Machine, pMachine^, SizeOf(string));
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_LOG_IN].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pLogin^.XQLMStruc.Stat;
if (SQLCode=0) then
begin
SessID := pLogin^.XQLMStruc.SessionId;
XQLMLoaded := TRUE;
end;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLLogin := SQLCode;
end;
function XQLLogout : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pXQLMStruc^, SizeOf(tXQLMStruc), #0);
with pXQLMStruc^ do
begin
XQLMID := XQLM_ID;
Fcn := FCN_LOG_OUT;
SessionID := SessID;
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_XQLM_STRUC].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pXQLMStruc^.Stat;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLLogout := SQLCode;
end;
function XQLCursor(var Cursor : integer) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pXQLMStruc^, SizeOf(tXQLMStruc), #0);
with pXQLMStruc^ do
begin
XQLMID := XQLM_ID;
Fcn := FCN_CURSOR;
CursorId := -1;
SessionID := SessID;
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_XQLM_STRUC].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
begin
SQLCode := pXQLMStruc^.Stat;
if (SQLCode=0) then
Cursor := pXQLMStruc^.CursorId;
end;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLCursor := SQLCode;
end;
function XQLCompile( Cursor : integer;
var SLen : integer;
var Stmnt ) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pCompile^, SizeOf(tCompileStruc), #0);
with pCompile^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_COMPILE;
CursorID := Cursor;
SessionID := SessID;
end;
with pCompile^.CompileRec do
begin
Statement.Offset := 0;
Statement.Segment := XQLMBuffer[1].DPMIAddr.Segment;
Len := SLen;
FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
Move(Stmnt, XQLMBuffer[1].Buffer^, SLen);
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_COMPILE].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pCompile^.XQLMStruc.Stat;
if (SQLCode<=0) then
SLen := pCompile^.CompileRec.Len;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLCompile := SQLCode;
end;
function XQLFormat( Cursor,
VPos,
Len : integer;
var MaskBuf ) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pFormat^, SizeOf(tFormatStruc), #0);
with pFormat^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_FORMAT;
CursorID := Cursor;
SessionID := SessID;
end;
with pFormat^.FormatRec do
begin
Position := VPos;
Mask.Offset := 0;
Mask.Segment := XQLMBuffer[1].DPMIAddr.Segment;
MaskLen := Len;
FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
Move(MaskBuf, XQLMBuffer[1].Buffer^, Len);
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_FORMAT].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pFormat^.XQLMStruc.Stat;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLFormat := SQLCode;
end;
function XQLFetch( Cursor,
Op : integer;
var DLen : integer;
var Buf;
var Sel : longint;
ASCII,
Spaces : integer ) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pFetch^, SizeOf(tFetchStruc), #0);
with pFetch^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_FETCH;
CursorID := Cursor;
SessionID := SessID;
end;
with pFetch^.FetchRec do
begin
Operation := OP;
DataLen := DLen;
Select := Sel;
ASCIIFlag := ASCII;
Spacing := Spaces;
DataBuf.Offset := 0;
DataBuf.Segment := XQLMBuffer[1].DPMIAddr.Segment;
FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #32);
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_FETCH].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pFetch^.XQLMStruc.Stat;
if (SQLCode<=0) then
begin
DLen := pFetch^.FetchRec.DataLen;
Sel := pFetch^.FetchRec.Select;
Move(XQLMBuffer[1].Buffer^, Buf, DLen);
end;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLFetch := SQLCode;
end;
function XQLDescribe( Cursor,
VPos : integer;
var DType,
Size,
Dec,
DSize,
NLength : integer;
var Name ) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pDescr^, SizeOf(tDescrStruc), #0);
with pDescr^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_DESCRIBE;
CursorID := Cursor;
SessionID := SessID;
end;
with pDescr^.DescrRec do
begin
Position := VPos;
NameLength := NLength;
NameBuf.Offset := 0;
NameBuf.Segment := XQLMBuffer[1].DPMIAddr.Segment;
FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
Move(Name, XQLMBuffer[1].Buffer^, NLength);
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_DESCRIBE].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pDescr^.XQLMStruc.Stat;
if (SQLCode<=0) then
begin
DType := pDescr^.DescrRec.DataType;
Size := pDescr^.DescrRec.DataSize;
Dec := pDescr^.DescrRec.DecCount;
DSize := pDescr^.DescrRec.DispSize;
NLength := pDescr^.DescrRec.NameLength;
Move(XQLMBuffer[1].Buffer^, Name, NLength);
end;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLDescribe := SQLCode;
end;
function XQLSubst( Cursor,
SCount,
NameLen : integer;
var VarName;
TextLen : integer;
var VarText ) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pSubst^, SizeOf(tSubstStruc), #0);
with pSubst^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_SUBST;
CursorID := Cursor;
SessionID := SessID;
end;
with pSubst^.SubstRec do
begin
VName.Offset := 0;
VName.Segment := XQLMBuffer[1].DPMIAddr.Segment;
NLen := NameLen;
VText.Offset := 0;
VText.Segment := XQLMBuffer[2].DPMIAddr.Segment;
TLen := TextLen;
FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
Move(VarName, XQLMBuffer[1].Buffer^, NameLen);
FillChar(XQLMBuffer[2].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
Move(VarText, XQLMBuffer[2].Buffer^, TextLen);
Count := SCount;
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_SUBST].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pSubst^.XQLMStruc.Stat;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLSubst := SQLCode;
end;
function XQLExec(Cursor:integer):integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pXQLMStruc^, SizeOf(tXQLMStruc), #0);
with pXQLMStruc^ do
begin
XQLMID := XQLM_ID;
Fcn := FCN_EXEC;
CursorID := Cursor;
SessionID := SessID;
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_XQLM_STRUC].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pXQLMStruc^.Stat;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLExec := SQLCode;
end;
function XQLFree(Cursor:integer):integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pXQLMStruc^, SizeOf(tXQLMStruc), #0);
with pXQLMStruc^ do
begin
XQLMID := XQLM_ID;
Fcn := FCN_FREE;
CursorID := Cursor;
SessionID := SessID;
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_XQLM_STRUC].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pXQLMStruc^.Stat;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLFree := SQLCode;
end;
function XQLStatus( Cursor,
SubFunc : integer;
var StatBuf ) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pStatus^, SizeOf(tStatusStruc), #0);
with pStatus^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_STAT;
CursorID := Cursor;
SessionID := SessID;
end;
with pStatus^.StatusRec do
begin
SubFunctn := SubFunc;
Buf.Offset := 0;
Buf.Segment := XQLMBuffer[1].DPMIAddr.Segment;
FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #32);
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_STAT].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pStatus^.XQLMStruc.Stat;
if (SQLCode<=0) then
Move(XQLMBuffer[1].Buffer^, StatBuf, STATUS_BUFFER_SIZE);
end
else
SQLCode := XQLM_NOT_LOADED;
XQLStatus := SQLCode;
end;
function XQLStop : integer;
begin
{ This func is not allowed in DPMI }
XQLStop := DPMI_INTERFACE_FAIL;
end;
function XQLVersion(VBuffer : longint) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pVersion^, SizeOf(tVersionStruc), #0);
with pVersion^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_VERS;
end;
with pVersion^.VersionRec do
begin
Buffer.Offset := 0;
Buffer.Segment := XQLMBuffer[1].DPMIAddr.Segment;
FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #32);
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_VERS].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pVersion^.XQLMStruc.Stat;
if (SQLCode<=0) then
Move(XQLMBuffer[1].Buffer^, VBuffer, SizeOf(LongInt));
end
else
SQLCode := XQLM_NOT_LOADED;
XQLVersion := SQLCode;
end;
function XQLConvert ( Option,
DType,
Size,
Dec,
DSize : integer;
var Value;
var RetValue;
var Mask;
Just : integer ) : integer;
var i : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pConvert^, SizeOf(tConvertStruc), #0);
with pConvert^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_CONV;
end;
with pConvert^.ConvertRec do
begin
ConvFcn := Option;
ConvType := DType;
ConvSize := Size;
ConvDec := Dec;
ConvDSize := DSize;
ConvJust := Just;
ConvVal.Offset := 0;
ConvVal.Segment := XQLMBuffer[1].DPMIAddr.Segment;
ConvRet.Offset := 0;
ConvRet.Segment := XQLMBuffer[2].DPMIAddr.Segment;
ConvMask.Offset := 0;
ConvMask.Segment := XQLMBuffer[3].DPMIAddr.Segment;
Move(Value, XQLMBuffer[1].Buffer^, pred(SQL_WORK_BUFFER_SIZE));
FillChar(XQLMBuffer[2].Buffer^, SQL_WORK_BUFFER_SIZE, #32);
Move(Mask, XQLMBuffer[3].Buffer^, pred(SQL_WORK_BUFFER_SIZE));
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_CONV].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pConvert^.XQLMStruc.Stat;
if (SQLCode<=0) then
begin
i := 0;
while (XQLMBuffer[2].Buffer^[i]<>#0) and (i<SQL_WORK_BUFFER_SIZE) do
inc(i);
Move(XQLMBuffer[2].Buffer^,RetValue,i);
end;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLConvert := SQLCode;
end;
function XQLValidate(var Count : integer;
var FieldName;
BufLen : integer;
var Data ) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pValidate^, SizeOf(tValidateStruc), #0);
with pValidate^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_VAL;
end;
with pValidate^.ValidateRec do
begin
ValCount := Count;
ValBufLen := BufLen;
ValField.Offset := 0;
ValField.Segment := XQLMBuffer[1].DPMIAddr.Segment;
ValData.Offset := 0;
ValData.Segment := XQLMBuffer[2].DPMIAddr.Segment;
Move(FieldName, XQLMBuffer[1].Buffer^, pred(SQL_WORK_BUFFER_SIZE));
FillChar(XQLMBuffer[2].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
Move(Data, XQLMBuffer[2].Buffer^, BufLen);
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_VAL].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pValidate^.XQLMStruc.Stat;
if (SQLCode<=0) then
Count := pValidate^.ValidateRec.ValCount;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLValidate := SQLCode;
end;
function XQLMask( Option,
DType,
Size,
Dec : integer;
var MLen : integer;
var Mask ) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pMask^, SizeOf(tMaskStruc), #0);
with pMask^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_MASK;
end;
with pMask^.MaskRec do
begin
MaskOption := Option;
MaskType := DType;
MaskSize := Size;
MaskDec := Dec;
MaskLen := MLen;
MaskVal.Offset := 0;
MaskVal.Segment := XQLMBuffer[1].DPMIAddr.Segment;
FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #0);
Move(Mask, XQLMBuffer[1].Buffer^, MLen);
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_MASK].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pMask^.XQLMStruc.Stat;
if (SQLCode<=0) then
begin
MLen := pMask^.MaskRec.MaskLen;
Move(XQLMBuffer[1].Buffer^, Mask, MLen);
end;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLMask := SQLCode;
end;
function XQLSpUtility( Cursor,
Option : integer;
var StmntCnt,
StmntExec : integer;
var BufLen : integer;
var StatBuf ) : integer;
begin
SQLCode := DPMI_INTERFACE_FAIL;
if XQLMLoaded then
begin
FillChar(pSpUtil^, SizeOf(tSpUtilStruc), #0);
with pSpUtil^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Fcn := FCN_SPUTIL;
CursorID := Cursor;
SessionID := SessID;
end;
with pSpUtil^.SpUtilRec do
begin
UtilOption := Option;
UtilStmntCnt := StmntCnt;
UtilStmntExec := StmntExec;
UtilBufLen := BufLen;
UtilStatBuf.Offset := 0;
UtilStatBuf.Segment := XQLMBuffer[1].DPMIAddr.Segment;
FillChar(XQLMBuffer[1].Buffer^, SQL_WORK_BUFFER_SIZE, #32);
Move(StatBuf, XQLMBuffer[1].Buffer^, BufLen);
end;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_SPUTIL].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
SQLCode := pSpUtil^.XQLMStruc.Stat;
if (SQLCode<=0) then
begin
StmntCnt := pSpUtil^.SpUtilRec.UtilStmntCnt;
StmntExec := pSpUtil^.SpUtilRec.UtilStmntExec;
BufLen := pSpUtil^.SpUtilRec.UtilBufLen;
Move(XQLMBuffer[2].Buffer^,StatBuf,BufLen);
end;
end
else
SQLCode := XQLM_NOT_LOADED;
XQLSpUtility := SQLCode;
end;
{************************************************************************}
{***** internal: initing and allocating buffers in lower dos memory *****}
{************************************************************************}
function AllocDosXQLBuf(var DosAlloc : tDosAlloc;
var BufferPtr : pXQLMArray) : boolean;
begin
AllocDosXQLBuf := FALSE;
BufferPtr := NIL;
DosAlloc.Addresses := GlobalDosAlloc(SQL_WORK_BUFFER_SIZE);
if (DosAlloc.Addresses=0) then
exit;
BufferPtr := Ptr(DosAlloc.Selector,0);
FillChar(BufferPtr^, SQL_WORK_BUFFER_SIZE, #0);
{ No exit: everything works fine }
AllocDosXQLBuf := TRUE;
end;
procedure DeallocDosXQLBuf(var BufferPtr : pXQLMArray;
var DosAlloc : tDosAlloc );
var res : integer;
begin
if (BufferPtr<>NIL) then
begin
res := GlobalDosFree(DosAlloc.Segment);
BufferPtr := NIL;
DosAlloc.Addresses := 0;
end;
end;
function AllocDosStrBuf(var SegOfs : tSegOfs;
var BufferPtr : pString ) : boolean;
var DosAlloc : tDosAlloc;
begin
AllocDosStrBuf := FALSE;
SegOfs.Offset := 0;
SegOfs.Segment := 0;
BufferPtr := NIL;
DosAlloc.Addresses := GlobalDosAlloc(SizeOf(string));
if (DosAlloc.Addresses=0) then
exit;
BufferPtr := Ptr(DosAlloc.Selector,0);
SegOfs.Segment := DosAlloc.Segment;
FillChar(BufferPtr^, SizeOf(string), #0);
{ No exit: everything works fine }
AllocDosStrBuf := TRUE;
end;
procedure DeallocDosStrBuf(var BufferPtr : pString; SegOfs:tSegOfs);
var res : integer;
begin
if (BufferPtr<>NIL) then
begin
res := GlobalDosFree(SegOfs.Segment);
BufferPtr := NIL;
end;
end;
function AllocDosIntBuf(var IntVar;
var SegOfs : tSegOfs;
var BufferPtr : pInteger ) : boolean;
var DosAlloc : tDosAlloc;
begin
AllocDosIntBuf := FALSE;
SegOfs.Offset := 0;
SegOfs.Segment := 0;
BufferPtr := NIL;
DosAlloc.Addresses := GlobalDosAlloc(SizeOf(integer));
if (DosAlloc.Addresses=0) then
exit;
BufferPtr := Ptr(DosAlloc.Selector,0);
SegOfs.Segment := DosAlloc.Segment;
Move(IntVar, BufferPtr^, SizeOf(integer));
{ No exit: everything works fine }
AllocDosIntBuf := TRUE;
end;
procedure DeallocDosIntBuf(var BufferPtr : pInteger; SegOfs:tSegOfs);
var res : integer;
begin
if (BufferPtr<>NIL) then
begin
res := GlobalDosFree(SegOfs.Segment);
BufferPtr := NIL;
end;
end;
function BTRAvail : boolean;
begin
Regs := DefaultRMR;
Regs.AX := $3500 + BTR_INT;
if SimRMI.SimRealModeInt(DOS_INT,@Regs) then
BTRAvail := (Regs.BX=BTR_OFFSET)
else
BTRAvail := FALSE;
end;
function XQLMAvail : boolean;
begin
SQLCode := XQLM_NOT_LOADED;
with pBtrieve^.XQLMStruc do
begin
XQLMID := XQLM_ID;
Stat := -1;
Fcn := FCN_INV;
CursorId := 0;
SessionID := SessID;
end;
with pBtrieve^.BtrieveRec do
BtrOp := FCN_INV;
Regs := DefaultRMR;
Regs.DS := XQLMFuncs[FCN_BTRIEVE].Segment;
if SimRMI.SimRealModeInt(BTR_INT,@Regs) then
if (pBtrieve^.XQLMStruc.Stat=FCN_RES_INV_XQLM) then
SQLCode := 0;
XQLMAvail := (SQLCode=0);
end;
function InitXQLMDPMI : integer;
var i : integer;
ok : boolean;
begin
InitXQLMDPMI := BTRV_NOT_LOADED;
for i := 1 to XQLMBUFFS do
begin
XQLMBuffer[i].DPMIAddr.Addresses := 0;
XQLMBuffer[i].Buffer := NIL;
end;
for i := FCN_LOG_IN to FCN_BTRIEVE do
XQLMFuncs[i].Addresses := 0;
pXQLMStruc := NIL;
pBtrieve := NIL;
pBtrStat := NIL;
pLogin := NIL;
pUserID := NIL;
pPswd := NIL;
pDataDic := NIL;
pDataPath := NIL;
pMachine := NIL;
pCompile := NIL;
pFormat := NIL;
pFetch := NIL;
pDescr := NIL;
pSubst := NIL;
pStatus := NIL;
pVersion := NIL;
pConvert := NIL;
pValidate := NIL;
pMask := NIL;
pSpUtil := NIL;
{ work buffer's allocation }
i := 1;
ok := TRUE;
while (i<=XQLMBUFFS) and ok do
begin
ok := AllocDosXQLBuf(XQLMBuffer[i].DPMIAddr,XQLMBuffer[i].Buffer);
inc(i);
end;
{ btrieve func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_BTRIEVE].Addresses := GlobalDosAlloc(SizeOf(tBtrieveStruc));
if (XQLMFuncs[FCN_BTRIEVE].Addresses<>0) then
begin
pBtrieve := ptr(XQLMFuncs[FCN_BTRIEVE].Selector,0);
{ btrieve func status buffer allocation }
ok := AllocDosIntBuf(BStat, pBtrieve^.BtrieveRec.BtrStat, pBtrStat);
end
else
ok := FALSE;
end;
{ login func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_LOG_IN].Addresses := GlobalDosAlloc(SizeOf(tLoginStruc));
if (XQLMFuncs[FCN_LOG_IN].Addresses<>0) then
begin
pLogin := ptr(XQLMFuncs[FCN_LOG_IN].Selector,0);
{ login func string buffer's allocation }
ok := AllocDosStrBuf(pLogin^.LoginRec.UserID, pUserID ) and
AllocDosStrBuf(pLogin^.LoginRec.Pswd, pPswd ) and
AllocDosStrBuf(pLogin^.LoginRec.DataDic, pDataDic ) and
AllocDosStrBuf(pLogin^.LoginRec.DataPath, pDataPath) and
AllocDosStrBuf(pLogin^.LoginRec.Machine, pMachine );
end
else
ok := FALSE;
end;
{ Logout func buffer allocation. Used also from the following func's:}
{ Cursor, Exec, Free, }
if ok then
begin
XQLMFuncs[FCN_XQLM_STRUC].Addresses := GlobalDosAlloc(SizeOf(tXQLMStruc));
if (XQLMFuncs[FCN_XQLM_STRUC].Addresses<>0) then
pXQLMStruc := ptr(XQLMFuncs[FCN_XQLM_STRUC].Selector,0)
else
ok := FALSE;
end;
{ Compile func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_COMPILE].Addresses := GlobalDosAlloc(SizeOf(tCompileStruc));
if (XQLMFuncs[FCN_COMPILE].Addresses<>0) then
pCompile := ptr(XQLMFuncs[FCN_COMPILE].Selector,0)
else
ok := FALSE;
end;
{ Format func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_FORMAT].Addresses := GlobalDosAlloc(SizeOf(tFormatStruc));
if (XQLMFuncs[FCN_FORMAT].Addresses<>0) then
pFormat := ptr(XQLMFuncs[FCN_FORMAT].Selector,0)
else
ok := FALSE;
end;
{ Fetch func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_FETCH].Addresses := GlobalDosAlloc(SizeOf(tFetchStruc));
if (XQLMFuncs[FCN_FETCH].Addresses<>0) then
pFetch := ptr(XQLMFuncs[FCN_FETCH].Selector,0)
else
ok := FALSE;
end;
{ Describe func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_DESCRIBE].Addresses := GlobalDosAlloc(SizeOf(tDescrStruc));
if (XQLMFuncs[FCN_DESCRIBE].Addresses<>0) then
pDescr := ptr(XQLMFuncs[FCN_DESCRIBE].Selector,0)
else
ok := FALSE;
end;
{ Subst func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_SUBST].Addresses := GlobalDosAlloc(SizeOf(tSubstStruc));
if (XQLMFuncs[FCN_SUBST].Addresses<>0) then
pSubst := ptr(XQLMFuncs[FCN_SUBST].Selector,0)
else
ok := FALSE;
end;
{ Status func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_STAT].Addresses := GlobalDosAlloc(SizeOf(tStatusStruc));
if (XQLMFuncs[FCN_STAT].Addresses<>0) then
pStatus := ptr(XQLMFuncs[FCN_STAT].Selector,0)
else
ok := FALSE;
end;
{ Version func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_VERS].Addresses := GlobalDosAlloc(SizeOf(tVersionStruc));
if (XQLMFuncs[FCN_VERS].Addresses<>0) then
pVersion := ptr(XQLMFuncs[FCN_VERS].Selector,0)
else
ok := FALSE;
end;
{ Convert func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_CONV].Addresses := GlobalDosAlloc(SizeOf(tConvertStruc));
if (XQLMFuncs[FCN_CONV].Addresses<>0) then
pConvert := ptr(XQLMFuncs[FCN_CONV].Selector,0)
else
ok := FALSE;
end;
{ Validate func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_VAL].Addresses := GlobalDosAlloc(SizeOf(tValidateStruc));
if (XQLMFuncs[FCN_VAL].Addresses<>0) then
pValidate := ptr(XQLMFuncs[FCN_VAL].Selector,0)
else
ok := FALSE;
end;
{ Mask func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_MASK].Addresses := GlobalDosAlloc(SizeOf(tMaskStruc));
if (XQLMFuncs[FCN_MASK].Addresses<>0) then
pMask := ptr(XQLMFuncs[FCN_MASK].Selector,0)
else
ok := FALSE;
end;
{ SpUtil func buffer allocation }
if ok then
begin
XQLMFuncs[FCN_SPUTIL].Addresses := GlobalDosAlloc(SizeOf(tSpUtilStruc));
if (XQLMFuncs[FCN_SPUTIL].Addresses<>0) then
pSpUtil := ptr(XQLMFuncs[FCN_SPUTIL].Selector,0)
else
ok := FALSE;
end;
if ok then
begin
if BTRAvail then
begin
if XQLMAvail then
XQLMLoaded := TRUE
else
begin
InitXQLMDPMI := XQLM_NOT_LOADED;
ok := FALSE;
end;
end
else
ok := FALSE;
end;
if (not ok) then
begin
InitXQLMDPMI := DPMI_INTERFACE_FAIL;
ExitXQLMDPMI;
exit;
end;
InitXQLMDPMI := 0;
end;
procedure ExitXQLMDPMI;
var i : integer;
begin
XQLMLoaded := FALSE;
if (pSpUtil<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_SPUTIL].Segment);
pSpUtil := NIL;
end;
if (pMask<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_MASK].Segment);
pMask := NIL;
end;
if (pValidate<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_VAL].Segment);
pValidate := NIL;
end;
if (pValidate<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_VAL].Segment);
pValidate := NIL;
end;
if (pConvert<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_CONV].Segment);
pConvert := NIL;
end;
if (pVersion<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_VERS].Segment);
pVersion := NIL;
end;
if (pStatus<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_STAT].Segment);
pStatus := NIL;
end;
if (pSubst<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_SUBST].Segment);
pSubst := NIL;
end;
if (pDescr<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_DESCRIBE].Segment);
pDescr := NIL;
end;
if (pFetch<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_FETCH].Segment);
pFetch := NIL;
end;
if (pFormat<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_FORMAT].Segment);
pFormat := NIL;
end;
if (pCompile<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_COMPILE].Segment);
pCompile := NIL;
end;
if (pXQLMStruc<>NIL) then
begin
i := GlobalDosFree(XQLMFuncs[FCN_XQLM_STRUC].Segment);
pXQLMStruc := NIL;
end;
if (pLogin<>NIL) then
begin
DeallocDosStrBuf(pMachine, pLogin^.LoginRec.Machine);
DeallocDosStrBuf(pDataPath, pLogin^.LoginRec.DataPath);
DeallocDosStrBuf(pDataDic, pLogin^.LoginRec.DataDic);
DeallocDosStrBuf(pPswd, pLogin^.LoginRec.Pswd);
DeallocDosStrBuf(pUserID, pLogin^.LoginRec.UserID);
i := GlobalDosFree(XQLMFuncs[FCN_LOG_IN].Segment);
pLogin := NIL;
end;
if (pBtrieve<>NIL) then
begin
DeallocDosIntBuf(pBtrStat, pBtrieve^.BtrieveRec.BtrStat);
i := GlobalDosFree(XQLMFuncs[FCN_BTRIEVE].Segment);
pBtrieve := NIL;
end;
for i := XQLMBUFFS downto 1 do
DeallocDosXQLBuf(XQLMBuffer[i].Buffer,XQLMBuffer[i].DPMIAddr);
end;
end.